<!DOCTYPE html>
<html>
<head lang="en">
    <meta charset="UTF-8">
    <title></title>
</head>
<body>
<script>
    //利用空对象做介质
    function extend(child, parent) {
        var f = function () {
        };
        f.prototype = parent.prototype;
        child.prototype = new f();
        child.prototype.constructor = child;
        child.uber = parent.prototype;//在子对象上打开一条通道，可以直接调用父对象的方法
    }
    //复制prototype
    function extend2(child,parent){
        var cp = child.prototype;
        var pp = parent.prototype;
        for(var i in pp){
            cp[i] = pp[i];
        }
        child.uber = pp;
    }

    function cat(name) {
        this.name = name;
    }
    function animal(name) {
        this.name = name;
    }
    animal.prototype.species = "cat";
    animal.prototype.color = "brown";
//    extend(cat, animal);
//    var cat1 = new cat("catName");
//    console.log(cat1.species);
//    console.log(cat.uber);
    extend2(cat,animal);
    var cat1 = new cat("catName");
    console.log(cat1.species);
    console.log(cat.uber);
    console.log(cat.prototype);


    //非构造函数的继承
    var china = {
        "nation":"china"
    }
    var doctor = {
        "career":"doctor"
    }

    function object(o){
        function f (){}
        f.prototype = o ;
        return new f();
    }
    var doc1 = object(china);
    doc1.doctor = "医生";
    console.log(doc1);

    //深拷贝
    function deepCopy(p, c) {
        var c = c || {};
        for (var i in p) {
            if (typeof p[i] === 'object') {
                c[i] = (p[i].constructor === Array) ? [] : {};
                deepCopy(p[i], c[i]);
            } else {
                c[i] = p[i];
            }
        }
        return c;
    }

</script>

</body>
</html>